package com.abc.mapper;

import com.abc.entity.Chengji;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

public interface ChengjiMapper {

    //查询所有学生成绩
    @Select("select kc.mingcheng as kcmc,kc.id as kcid,xs.xingming as xsxm,xs.id as xsid,cj.chengji as cjcj from chengji as cj " +
            "left join kecheng as kc on cj.kechengid = kc.id " +
            "left join xuesheng as xs on xs.id = cj.xueshengid " +
            " where xueshengid in( select xs.id as xsid from jiaoshi as js  left join xueshengjiaoshi as xsjs on js.id = xsjs.jiaoshiid left join xuesheng as xs on xs.id = xsjs.xueshengid where js.id=#{jsid} )")
    List<Map<String,Object>> findAllChengji(String jsid );
    //查询所有学生成绩
    @Select("select kc.mingcheng as kcmc,kc.id as kcid,xs.xingming as xsxm,xs.id as xsid,cj.chengji as cjcj from chengji as cj " +
            "left join kecheng as kc on cj.kechengid = kc.id " +
            "left join xuesheng as xs on xs.id = cj.xueshengid " +
            " where xueshengid in( select xs.id as xsid from jiaoshi as js  left join xueshengjiaoshi as xsjs on js.id = xsjs.jiaoshiid left join xuesheng as xs on xs.id = xsjs.xueshengid where xs.id=#{jsid} )")
    List<Map<String,Object>> findXsAllChengji(String xsid );
    //新增成绩
    @Insert("insert into chengji(kechengid,xueshengid,chengji) values(#{kechengid},#{xueshengid},#{chengji})")
    int insertChengji(Chengji chengji);
    //修改成绩
    @Update("update chengji set chengji=#{chengji} where kechengid=#{kechengid} and xueshengid = #{xueshengid}")
    int updateChengji(Chengji chengji);
    @Select("select * from chengji where kechengid=#{kechengid} and xueshengid = #{xueshengid}")
    Chengji findByChengjiId(Chengji chengji);

}
